<?php

defined('BY_JYA') or exit('error');
list($goodsid, $optionid = 0, $realprice = true, $openid = '')=$arguments;
$redis = redis();
		if (is_error($redis)) 
		{
			return false;
		}
		static $deletedSeckill;
		if (is_null($deletedSeckill)) 
		{
			$this->deleteSeckill();
			$deletedSeckill = true;
		}
		$id = $this->getTodaySeckill();
		if (empty($id)) 
		{
			return false;
		}
		$times = $this->getTaskTimes($id);
		$options = array();
		$currenttime = time();
		$timegoods = array();
		$sktime = 0;
		$timeid = 0;
		$roomid = 0;
		$taskid = 0;
		$goods_starttime = 0;
		$goods_endtime = 0;
		foreach ($times as $key => $time ) 
		{
			$starttime = strtotime(date('Y-m-d ' . $time['time'] . ':00:00'));
			if (isset($times[$key + 1])) 
			{
				$end = $times[$key + 1]['time'] - 1;
				$endtime = strtotime(date('Y-m-d ' . $end . ':59:59'));
			}
			else 
			{
				$endtime = strtotime(date('Y-m-d 23:59:59'));
			}
			$time['endtime'] = $endtime;
			$time['starttime'] = $starttime;
			if (($starttime <= $currenttime) && ($currenttime <= $endtime)) 
			{
				$timeid = $time['id'];
				$taskid = $time['taskid'];
				$goods_starttime = $starttime;
				$goods_endtime = $endtime;
				$sktime = $time['time'];
				$timegoods = $this->getSeckillGoods($id, $time['time'], $goodsid);
			}
			else if ($currenttime < $starttime) 
			{
				if (empty($timegoods)) 
				{
					$timeid = $time['id'];
					$goods_starttime = $starttime;
					$goods_endtime = $endtime;
					$taskid = $time['taskid'];
					$sktime = $time['time'];
					$timegoods = $this->getSeckillGoods($id, $time['time'], $goodsid);
				}
			}
		}
		$total = 0;
		$count = 0;
		$selfcount = 0;
		$selftotalcount = 0;
		$maxbuy = 0;
		$notpay = 0;
		$selfnotpay = 0;
		$selftotalnotpay = 0;
		$totalmaxbuy = 0;
		if (!(empty($timegoods))) 
		{
			$roomid = $timegoods[0]['roomid'];
			$total = $timegoods[0]['total'];
			$price = $timegoods[0]['price'];
			$totalmaxbuy = $timegoods[0]['totalmaxbuy'];
			if (count($timegoods) <= 1) 
			{
				$counts = $this->getSeckillCount($id, $timeid, $timegoods[0]['goodsid'], 0, $openid);
				$count = $counts['count'];
				$selfcount = $counts['selfcount'];
				$selftotalcount = $counts['selftotalcount'];
				$notpay = $counts['notpay'];
				$selfnotpay = $counts['selfnotpay'];
				$selftotalnotpay = $counts['selftotalnotpay'];
				$maxbuy = $timegoods[0]['maxbuy'];
				$percent = ceil(($count / ((empty($total) ? 1 : $total))) * 100);
			}
			else 
			{
				$total = 0;
				$price = $timegoods[0]['price'];
				$option_goods = NULL;
				if (!(empty($optionid))) 
				{
					foreach ($timegoods as $g ) 
					{
						if ($g['optionid'] == $optionid) 
						{
							$total = $g['total'];
							$counts = $this->getSeckillCount($id, $timeid, $g['goodsid'], $optionid, $openid);
							$count = $counts['count'];
							$selfcount = $counts['selfcount'];
							$selftotalcount = $counts['selftotalcount'];
							$selfnotpay = $counts['selfnotpay'];
							$selftotalnotpay = $counts['selftotalnotpay'];
							$notpay = $counts['notpay'];
							$maxbuy = $g['maxbuy'];
							$percent = ceil(($count / ((empty($g['total']) ? 1 : $g['total']))) * 100);
							break;
						}
					}
				}
				else 
				{
					foreach ($timegoods as $g ) 
					{
						$total += $g['total'];
						if ($g['price'] <= $price) 
						{
							$price = $g['price'];
						}
						$options[] = $g;
					}
					$counts = $this->getSeckillCount($id, $timeid, $g['goodsid'], 0, $openid);
					$count = $counts['count'];
					$selfcount = $counts['selfcount'];
					$selfnotpay = $counts['selfnotpay'];
					$notpay = $counts['notpay'];
					$selftotalcount = $counts['selftotalcount'];
					$selftotalnotpay = $counts['selftotalnotpay'];
					$percent = ceil(($count / ((empty($total) ? 1 : $total))) * 100);
				}
			}
			if (!($realprice)) 
			{
				$price = price_format($price);
			}
			$tag = '';
			$taskinfo = $this->getTaskInfo($taskid);
			$roominfo = $this->getRoomInfo($taskid, $roomid);
			if (!(empty($taskinfo['tag']))) 
			{
				$tag = $taskinfo['tag'];
			}
			if (!(empty($roominfo['tag']))) 
			{
				$tag = $roominfo['tag'];
			}
			$status = false;
			if (($goods_starttime <= $currenttime) && ($currenttime <= $goods_endtime)) 
			{
				$status = 0;
			}
			else if ($currenttime < $goods_starttime) 
			{
				$status = 1;
			}
			else if ($goods_endtime < $currenttime) 
			{
				$status = -1;
			}
			return array('taskid' => $taskid, 'roomid' => $roomid, 'timeid' => $timeid, 'total' => $total, 'count' => $count, 'selfcount' => $selfcount, 'selftotalcount' => $selftotalcount, 'notpay' => $notpay, 'selfnotpay' => $selfnotpay, 'selftotalnotpay' => $selftotalnotpay, 'maxbuy' => $maxbuy, 'totalmaxbuy' => $totalmaxbuy, 'tag' => $tag, 'time' => $sktime, 'options' => $options, 'starttime' => $goods_starttime, 'endtime' => $goods_endtime, 'price' => $price, 'percent' => $percent, 'status' => $status);
		}
		return false;
